﻿using System;
namespace Producers.Ehr.Xtee.Riik.Ee.Producer.Ehr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="katastriyksuse_teatisParingType", Namespace="http://producers.ehr.xtee.riik.ee/producer/ehr", Target=typeof(KatastriyksuseTeatisParingType))]
    public class KatastriyksuseTeatisParingTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IKatastriyksuseTeatisParingType clazz;
        
        public KatastriyksuseTeatisParingTypeSerializer(IKatastriyksuseTeatisParingType clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("EHIT_ID");
            if (clazz.EHITID!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.EHITID))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : EHITID");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("katastriyksus");
            if (clazz.Katastriyksus!=null) {
                Writer.WriteTypeAttribute("http://producers.ehr.xtee.riik.ee/producer/ehr", "KY_tunnusType");
                Writer.WriteString(clazz.Katastriyksus.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Katastriyksus");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("anes_id");
            if (clazz.AnesId!=null) {
                Writer.WriteTypeAttribute("http://producers.ehr.xtee.riik.ee/producer/ehr", "anesKlassifikaator");
                Writer.WriteString(clazz.AnesId.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : AnesId");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("telefon");
            if (clazz.Telefon!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Telefon))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Telefon");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("epost");
            if (clazz.Epost!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Epost))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Epost");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="EHIT_ID") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>katastriyksuse_teatisParingType>EHIT_ID");
                }
                clazz.EHITID = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("EHIT_ID")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>katastriyksuse_teatisParingType>EHIT_ID", Reader.LocalName);
            }
            if (Reader.LocalName=="katastriyksus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>katastriyksuse_teatisParingType>katastriyksus");
                }
                clazz.Katastriyksus = new global::Producers.Ehr.Xtee.Riik.Ee.Producer.Ehr.KYTunnusType(Reader.ReadElementString("katastriyksus"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>katastriyksuse_teatisParingType>katastriyksus", Reader.LocalName);
            }
            if (Reader.LocalName=="anes_id") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>katastriyksuse_teatisParingType>anes_id");
                }
                clazz.AnesId = new global::Producers.Ehr.Xtee.Riik.Ee.Producer.Ehr.AnesKlassifikaator(Reader.ReadElementString("anes_id"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>katastriyksuse_teatisParingType>anes_id", Reader.LocalName);
            }
            if (Reader.LocalName=="telefon") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>katastriyksuse_teatisParingType>telefon");
                }
                clazz.Telefon = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("telefon")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>katastriyksuse_teatisParingType>telefon", Reader.LocalName);
            }
            if (Reader.LocalName=="epost") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>katastriyksuse_teatisParingType>epost");
                }
                clazz.Epost = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("epost")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>katastriyksuse_teatisParingType>epost", Reader.LocalName);
            }
        }
    }
}
